package com.yipei.business.controller;

import com.yipei.business.domain.MlLastHotNews;
import com.yipei.business.service.IMlLastHotNewsService;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.core.page.TableDataInfo;
import com.yipei.common.enums.BusinessType;
import com.yipei.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 必读新闻Controller
 *
 * @author yipei
 * @date 2024-12-21
 */
@RestController
@RequestMapping("/business/lastnews")
@Api(tags = "必读新闻", description = "必读新闻管理")
public class MlLastHotNewsController extends BaseController {
    @Autowired
    private IMlLastHotNewsService mlLastHotNewsService;

    /**
     * 查询必读新闻列表
     */
    //@PreAuthorize("@ss.hasPermi('business:lastnews:list')")
    @ApiOperation("必读新闻获取数据")
    @GetMapping("/list")
    public TableDataInfo list(MlLastHotNews mlLastHotNews) {
        startPage();
        List<MlLastHotNews> list = mlLastHotNewsService.selectMlLastHotNewsList(mlLastHotNews);
        return getDataTable(list);
    }

    /**
     * 导出必读新闻列表
     */
    //@PreAuthorize("@ss.hasPermi('business:lastnews:export')")
    @ApiOperation("必读新闻导出数据")
    @Log(title = "必读新闻", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MlLastHotNews mlLastHotNews) {
        List<MlLastHotNews> list = mlLastHotNewsService.selectMlLastHotNewsList(mlLastHotNews);
        ExcelUtil<MlLastHotNews> util = new ExcelUtil<MlLastHotNews>(MlLastHotNews.class);
        util.exportExcel(response, list, "必读新闻数据");
    }

    /**
     * 获取必读新闻详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:lastnews:query')")
    @ApiOperation("必读新闻通过ID获取数据")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mlLastHotNewsService.selectMlLastHotNewsById(id));
    }

    /**
     * 新增必读新闻
     */
    //@PreAuthorize("@ss.hasPermi('business:lastnews:add')")
    @ApiOperation("必读新闻删除数据")
    @Log(title = "必读新闻", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MlLastHotNews mlLastHotNews) {
        return toAjax(mlLastHotNewsService.insertMlLastHotNews(mlLastHotNews));
    }

    /**
     * 修改必读新闻
     */
    //@PreAuthorize("@ss.hasPermi('business:lastnews:edit')")
    @ApiOperation("必读新闻修改数据")
    @Log(title = "必读新闻", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MlLastHotNews mlLastHotNews) {
        return toAjax(mlLastHotNewsService.updateMlLastHotNews(mlLastHotNews));
    }

    /**
     * 删除必读新闻
     */
    //@PreAuthorize("@ss.hasPermi('business:lastnews:remove')")
    @ApiOperation("必读新闻删除数据")
    @Log(title = "必读新闻", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mlLastHotNewsService.deleteMlLastHotNewsByIds(ids));
    }
}
